﻿using MapReduceLib.Contracts;
using System.ServiceModel;
using MapReduceLib.DataModel;
using log4net;
using MasterNode.Interfaces;
using System.Collections.Generic;

namespace MasterNode.ServiceImpl
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single, IncludeExceptionDetailInFaults = true)]
    class JobManager : IJobManager
    {
        private static ILog Log = LogManager.GetLogger(typeof(JobManager));
        private const string ManifestFileName = "job.xml";
        private IJobRepository jobRepository;

        public JobManager(IJobRepository jobRepo)
        {
            this.jobRepository = jobRepo;
        }

        #region IJobManager Members

        public string EnqueueJob(byte[] compressedJob)
        {
            Job job = jobRepository.AddJob(compressedJob);
            return job.JobId;
        }

        public IEnumerable<Job> GetAvailableJobs()
        {
            return jobRepository.RegisteredJobs;
        }

        #endregion
    }
}